package love.yuanmengrobot.attendancesystem.servlet;
/*
 *   @Studio:CHJY · 源梦科技
 *   @Author:CHJY创幻
 *   @Ide:IntelliJ IDEA
 *   @Creation time:2021/6/24 23:38
 */

import com.google.gson.Gson;
import love.yuanmengrobot.attendancesystem.dao.MemberDao;
import love.yuanmengrobot.attendancesystem.dao.StudentAttendanceDao;
import love.yuanmengrobot.attendancesystem.entity.Member;
import love.yuanmengrobot.attendancesystem.entity.StudentAttendanceDate;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

public class StudentAttendanceServlet extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("get");
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String id = request.getParameter("memberid");
        PrintWriter pw = null;
        try {
            pw = response.getWriter();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Gson gson=new Gson();

        StudentAttendanceDao studentAttendanceDao=new StudentAttendanceDao();
        ArrayList<StudentAttendanceDate> sdate= studentAttendanceDao.queryByMemberId(id);
        if (sdate != null) {
            pw.print(gson.toJson(sdate));
        } else {
//            StudentAttendanceDate s=new StudentAttendanceDate();
//            pw.print("{\"meg\":\"查询失败\"}");
            ArrayList<StudentAttendanceDate> s=new   ArrayList<StudentAttendanceDate>();
            pw.print(gson.toJson(s));
        }
        pw.flush();
        pw.close();

    }
}
